<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <title>vue监视数据的原理-数组</title>
</head>

<body>
    <div id="root">
        <h1>学校信息</h1>
        <h2>学校：{{name}}</h2>
        <h2>地址：{{addres}}</h2>
        <hr>
        <h1>学生信息</h1>
        <button @click="addsex">添加性别信息</button>
        <h2>姓名：{{student.name}}</h2>
        <h2>年龄：真实年龄：{{student.age.zhenage}}，对外年龄：{{student.age.jiaage}}</h2>
        <h2 v-if="student.sex">性别：{{student.sex}}</h2>
        <hr>
        <h1>爱好</h1>
        <hr>
        <lu>
            <li v-for="(h,index) in student.hobby" :key="index">
                {{h}}
            </li>
        </lu>
        <h1>朋友信息</h1>
        <lu>
            <li v-for="(f,index) in student.friends" :key="index">
                {{f.name}}----{{f.age}}
            </li>
        </lu>
    </div>

    <script>
        const vm = new Vue({
            el: '#root',
            data: {
                name: '清华大学',
                addres: '五道口',
                student: {
                    sex: '',
                    name: '张三',
                    age: {
                        zhenage: '40',
                        jiaage: '20'
                    },
                    hobby: ['抽烟',
                        '喝酒', '烫头'
                    ],
                    friends: [{
                        name: '张三',
                        age: '20'
                    }, {
                        name: '李四',
                        age: '20'
                    }]

                }
            },
            methods: {
                addsex() {
                    //Vue.set(this.student, 'sex', "男")
                    vm.$set(this.student, 'sex', '女')
                }
            },
        })
    </script>
</body>

</html>